<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('operation_logs', function (Blueprint $table) {
            $table->id();

            $table->unsignedBigInteger('admin_id')->comment('管理员ID');
            $table->string('name', 50)->comment('管理员名称');

            $table->string('ip', 45)->comment('操作IP');
            $table->string('method', 10)->comment('请求方法');
            $table->string('url', 255)->comment('请求URL');
            $table->text('params')->nullable()->comment('请求参数');
            $table->text('response')->nullable()->comment('响应内容');
            $table->unsignedSmallInteger('status_code')->comment('响应状态码');
            $table->unsignedBigInteger('duration')->comment('请求持续时间，单位毫秒');
            $table->string('user_agent', 255)->nullable()->comment('用户代理');

            $table->timestamps();
            $table->comment('操作日志表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('operation_logs');
    }
};
